package com.instasale.services;

import com.instasale.dao.CarDAO;
import com.instasale.dao.SellerDAO;
import com.instasale.models.Car;
import com.instasale.models.Feature;
import com.instasale.models.Seller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
public class CarServiceImpl implements CarService {

    @Autowired
    private CarDAO carDAO;

    @Transactional
    public void addCar(Car car) {
        carDAO.addCar(car);
    }

    @Transactional
    public List<Car> listCar() {
        return carDAO.listCar();
    }

    @Transactional
    public List<Car> listCar(String orderByColumnName) {
        return carDAO.listCar(orderByColumnName);
    }

    @Transactional
    public void removeCar(Integer id) {
        carDAO.removeCar(id);
    }

    @Transactional
    public Car getById(Integer id) {
        return carDAO.getById(id);
    }

    public boolean isColumnExists(String columnName) {
        String[] columns = Car.getColumnNames();
        for (String column : columns)
            if (column.equalsIgnoreCase(columnName))
                return true;
        return false;
    }

}
